<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>file share</title>
  </head>
  <body>
    <button class="btn">file share</button>
    <input type="file">

    <script>
      const btnDom = document.querySelector('.btn')
      const iptDom = document.querySelector('input')
      let filesArray = []

      iptDom.addEventListener('change', (e) => {
        filesArray = e.target.files
      })
      btnDom.addEventListener('click', () => {
        if (navigator.canShare && navigator.canShare({ files: filesArray })) {
          navigator
            .share({
              files: filesArray,
              title: 'Vacation Pictures',
              text: 'Photos from September 27 to October 14.',
            })
            .then(() => console.log('Share was successful.'))
            .catch(error => console.log('Sharing failed', error))
        }
      })
    </script>
  </body>
</html>
